package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.dto.*;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FamilyListVo;
import com.zzyl.nursing.vo.FamilyMemberListVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/member/user")
@Api(tags =  "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IDeviceDataService deviceDataService;

    /**
     * 小程序登录
     * @param userLoginRequestDto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }

    /*
     * 绑定家人
     * */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody FamilyDto familyDto){
        familyMemberService.add(familyDto);
        return success();
    }

    /*
    * 查询家人列表
    * */
    @ApiOperation("查询家人列表")
    @GetMapping("/my")
    public AjaxResult list(){
        List<FamilyListVo> familyMemberlist = familyMemberService.listFamilyMembers();
        return success(familyMemberlist);
    }

    /*
    * 查询家人列表(分页查询)
    * */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public AjaxResult findByPage(
    @RequestParam(value = "pageNum", defaultValue = "1")Integer pageNum,
    @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize
    ){
        List<FamilyMemberListVo> familyMemberlist =  familyMemberService.findByPage(pageNum,pageSize);
        return success(familyMemberlist);
    }

    /*
     * 查询健康数据
     * */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult selectHealthData(@RequestBody DeviceDto deviceDto){
        Map<String, HealthDataDto>  list= familyMemberService.selectHealthData(deviceDto);
        return success(list);
   }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(QueryDeviceDataByDayDto queryDeviceDataByDayDto) {
        List<Map<String, Object>> list = familyMemberService.queryDeviceDataListByDay(queryDeviceDataByDayDto);

        return success().put("data", list).put("operationTime",null);
    }

    /**
     * 按周统计查询指标数据pageQueryAlertData
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(QueryDeviceDataByDayDto queryDeviceDataByDayDto) {
        List<Map<String, Object>> list = familyMemberService.queryDeviceDataListByWeek(queryDeviceDataByDayDto);

        return success().put("data", list).put("operationTime",null);
    }

    /*
    * 解除绑定
    * */
    @ApiOperation("解除绑定")
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(Long id){
       familyMemberService.deleteById(id);
        return success();
    }
}